home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 450_01 / CPPIMA / EXAMPLES / CAVERAGE.CC < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-24  |  2.0 KB  |  87 lines

  1. static const char rcs_id[] = "$Header: /disk1/schutte/src_tree/cppima/examples/RCS/caverage.cc,v 1.2 1994/06/07 15:20:16 schutte Exp schutte $";
  2. //    cppima: a C++ image processing library
  3.  
  4. //    Copyright (C) 1992  Klamer Schutte
  5.  
  6. //    klamer@mi.el.utwente.nl
  7.  
  8. //    This library is free software; you can redistribute it and/or
  9. //    modify it under the terms of the GNU Library General Public
  10. //    License as published by the Free Software Foundation; either
  11. //    version 2 of the License, or (at your option) any later version.
  12.  
  13. //    This library is distributed in the hope that it will be useful,
  14. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. //    Library General Public License for more details.
  17.  
  18. //    You should have received a copy of the GNU Library General Public
  19. //    License along with this library; if not, write to the Free
  20. //    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.  
  23. // $Log: caverage.cc,v $
  24. // Revision 1.2  1994/06/07  15:20:16  schutte
  25. // Changed from VIFF to IMA.
  26. //
  27. // Revision 1.1  1992/09/25  15:35:30  klamer
  28. // Initial revision
  29. //
  30.  
  31. // Program to calculate the average value of an image.
  32.  
  33. #include    <iostream.h>
  34.  
  35. #include    <cppima/charimaimage.h>
  36. #include    <cppima/imageiter.h>
  37. #include    <cppima/charimageiter.h>
  38.  
  39. double
  40. #ifdef __GNUG__
  41. // Sun C++ 2.1 Can't handle this kind of overloading.
  42. // (OK, it's on the edge...
  43. totalImagePixels( const CharImageBase &imm )
  44. #else
  45. totalImagePixels( const CharImaImage &imm )
  46. #endif
  47. {
  48.     CharImageIter    iter(imm);
  49.  
  50.     int    total = 0;
  51.     int    nr = 0;
  52.  
  53.     while(iter())
  54.     {
  55.         nr++;
  56.         total+=iter.read();
  57.     }
  58.  
  59.     return double(total) / nr;
  60. }
  61.  
  62. double
  63. totalImagePixels( const Image &imm )
  64. {
  65.     ImageIter    iter(imm);
  66.  
  67.     double    total = 0;
  68.     int    nr = 0;
  69.  
  70.     while(iter())
  71.     {
  72.         nr++;
  73.         total+=iter.readdouble();
  74.     }
  75.  
  76.     return total / nr;
  77. }
  78.  
  79. main(int , char *argv[])
  80. {
  81.     double     val = totalImagePixels(CharImaImage(argv[1]));
  82.  
  83.     cout << "Mean value of " << argv[1] << " is: " << val << endl;
  84. }
  85.  
  86.  
  87.